<template>
	<view>
		<block v-for="(item,index) in newsList" :key="index">
			<view class="news-item" @click="clickHandle(item.id)">
				<image :src="item.img_url"></image>
				<view class="right">
					<view class="title">
						{{item.title}}
					</view>
					<view class="info">
						<text>发表时间:   {{item.add_time | formatDate}}</text>
						<text>浏览:{{item.click}}</text>
					</view>
				</view>
			</view>
		</block>
	</view>
</template>

<script>
	export default {
		props: {
			newsList: {
				type: Array,
				default() {
					return []
				}
			}
		},
		methods: {
			clickHandle(id) {
				this.$emit('newClick',id)
			}
		},
		filters: {
			formatDate(date) {
				const nDate = new Date(date)
				const year = nDate.getFullYear()
				const month = nDate.getMonth() < 10 ? '0' + nDate.getMonth() : nDate.getMonth()
				const day = nDate.getDay() < 10 ? '0' + nDate.getDay() : nDate.getDay()
				return `${year}-${month}-${day}`
			}
		}
	}
</script>

<style lang="scss">
	.news-item {
		display: flex;
		padding: 10rpx;
		border-bottom: 4rpx solid #eee;
		image {
			min-width: 180rpx;
			max-width: 180rpx;
			height: 180rpx;
		}
		.right {
			margin-left: 10rpx;
			font-size: 28rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			.info {
				font-size: 24rpx;
				text:nth-child(2) {
					padding-left: 24rpx;
					color: red;
				}
			}
		}
	}
</style>
